
package brickbreaker;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.image.Image;
import javafx.util.Duration;

final class Config {

    static final Duration ANIMATION_TIME = Duration.millis(40);
    static final int MAX_LIVES = 9;
    // Screen info
    static final int FIELD_BRICK_IN_ROW = 15;

    static final String IMAGE_DIR = "images/desktop/";

    static final int WINDOW_BORDER = 3; // on desktop platform
    static final int TITLE_BAR_HEIGHT = 19; // on desktop platform
    static final int SCREEN_WIDTH = 960;
    static final int SCREEN_HEIGHT = 720;

     static final int INFO_TEXT_SPACE = 10;

    // Game field info
     static final int BRICK_WIDTH = 48;
     static final int BRICK_HEIGHT = 24;
     static final int SHADOW_WIDTH = 10;
     static final int SHADOW_HEIGHT = 16;

     static final double BALL_MIN_SPEED = 6;
     static final double BALL_MAX_SPEED = BRICK_HEIGHT;
     static final double BALL_MIN_COORD_SPEED = 2;
     static final double BALL_SPEED_INC = 0.5f;

     static final int BAT_Y = SCREEN_HEIGHT - 40;
     static final int BAT_SPEED = 8;

     static final int BONUS_SPEED = 3;

     static final int FIELD_WIDTH = FIELD_BRICK_IN_ROW * BRICK_WIDTH;
     static final int FIELD_HEIGHT = FIELD_WIDTH;
     static final int FIELD_Y = SCREEN_HEIGHT - FIELD_HEIGHT;

    private static final String[] BRICKS_IMAGES = new String[]{
            "blue.png",
            "broken1.png",
            "broken2.png",
            "brown.png",
            "cyan.png",
            "green.png",
            "grey.png",
            "magenta.png",
            "orange.png",
            "red.png",
            "violet.png",
            "white.png",
            "yellow.png",
    };

    private static ObservableList<Image> bricksImages = FXCollections.observableArrayList();

    static ObservableList<Image> getBricksImages() {
        return bricksImages;
    }

    private static final String[] BONUSES_IMAGES = new String[]{
            "ballslow.png",
            "ballfast.png",
            "catch.png",
            "batgrow.png",
            "batreduce.png",
            "ballgrow.png",
            "ballreduce.png",
            "strike.png",
            "extralife.png",
    };

    private static ObservableList<Image> bonusesImages = FXCollections.observableArrayList();

    static ObservableList<Image> getBonusesImages() {
        return bonusesImages;
    }

     static final int IMAGE_BACKGROUND = 0;
     static final int IMAGE_BAT_LEFT = 1;
     static final int IMAGE_BAT_CENTER = 2;
     static final int IMAGE_BAT_RIGHT = 3;
     static final int IMAGE_BALL_0 = 4;
     static final int IMAGE_LOGO = 10;
     static final int IMAGE_SPLASH_BRICK = 11;
     static final int IMAGE_SPLASH_BRICKSHADOW = 12;
     static final int IMAGE_SPLASH_BREAKER = 13;
     static final int IMAGE_SPLASH_BREAKERSHADOW = 14;
     static final int IMAGE_SPLASH_PRESSANYKEY = 15;
     static final int IMAGE_SPLASH_PRESSANYKEYSHADOW = 16;
     static final int IMAGE_SPLASH_STRIKE = 17;
     static final int IMAGE_SPLASH_STRIKESHADOW = 18;
     static final int IMAGE_SPLASH_SUN = 19;
     static final int IMAGE_READY = 20;
     static final int IMAGE_GAMEOVER = 21;

    private static final String[] IMAGES_NAMES = new String[]{
            "background.png",
            "bat/left.png",
            "bat/center.png",
            "bat/right.png",
            "ball/ball0.png",
            "ball/ball1.png",
            "ball/ball2.png",
            "ball/ball3.png",
            "ball/ball4.png",
            "ball/ball5.png",
            "logo.png",
            "splash/brick.png",
            "splash/brickshadow.png",
            "splash/breaker.png",
            "splash/breakershadow.png",
            "splash/pressanykey.png",
            "splash/pressanykeyshadow.png",
            "splash/strike.png",
            "splash/strikeshadow.png",
            "splash/sun.png",
            "ready.png",
            "gameover.png",
    };

    private static ObservableList<Image> images =FXCollections.observableArrayList();

    static ObservableList<Image> getImages() {
        return images;
    }

    static void initialize() {
        for (String imageName : IMAGES_NAMES) {
            Image image = new Image(Config.class.getResourceAsStream(IMAGE_DIR + imageName));
            if (image.isError()) {
                System.out.println("Image " + imageName + " not found");
            }
            images.add(image);
        }
        for (String imageName : BRICKS_IMAGES) {
            final String url = IMAGE_DIR + "brick/" + imageName;
            Image image = new Image(Config.class.getResourceAsStream(url));
            if (image.isError()) {
                System.out.println("Image " + url + " not found");
            }
            bricksImages.add(image);
        }
        for (String imageName : BONUSES_IMAGES) {
            final String url = IMAGE_DIR + "bonus/" + imageName;
            Image image = new Image(Config.class.getResourceAsStream(url));
            if (image.isError()) {
                System.out.println("Image " + url + " not found");
            }
            bonusesImages.add(image);
        }
    }

    private Config() {
    }

}

